/****************************************************************
 *  ColumnPickerButton
 *  Author: Felix Woo
 *  Date: 11-08-2007
 ****************************************************************/
//jsx3.require("tibco.spm.public.Button");
jsx3.Class.defineClass(
  "com.gix.gui.ColumnPickerButton",
  com.gix.gui.Button,
  null,
  function(control) {
    control.prototype.init = function(strName,intLeft,intTop,intWidth,strText) {
      this.jsxsuper(strName,intLeft,intTop,intWidth,strText);
    }

    control.prototype.getTargetMatrixName = function() {
      return this.targetMatrixName;
    }

    control.prototype.setTargetMatrixName = function(targetMatrixName) {
      delete this.targetObject;
      this.targetMatrixName = targetMatrixName;
    }

    control.prototype.setExclusions = function(listUneditableCols, listExcludedCols) {
        this.uneditable = listUneditableCols;
        this.excluded = listExcludedCols;
    }

    control.prototype.loadColumnPicker = function() {
      if(this.cp) {
          this.cp.actuallyClose();
          return;
      }
      if(!this.targetObject) {
      if(!this.targetMatrixName) {
        alert("Please specify the target matrix.");
        return;
      }

      this.targetObject = tibco.admin.Main.getServer().getJSXByName(this.targetMatrixName);
      if(!this.targetObject) {
          try {
              var vars = new Object();
              vars["objJSX"] = this;
              this.targetObject = jsx3.eval(this.targetMatrixName, vars);
          }
          catch(ex) {
              tibco.admin.Main.logException(ex);
          }
      }
      if(!this.targetObject) {
        alert("Cannot find the target object.");
        return;
      }
      if(!(this.targetObject instanceof jsx3.gui.Matrix)) {
        delete this.targetObject;
        alert("The target object is not an instance of jsx3.gui.Matrix.");
        return;
      }
      }
      this.cp = tibco.admin.Main.getServer().getRootBlock().load("jsxaddin://user!MatrixAdmin/components/columnPicker.xml");
      this.cp.initialize(this, this.targetObject, this.uneditable, this.excluded);
    }

    control.prototype.columnPickerClosed = function(obj) {
        if(obj == this.cp) {
            var changed = this.cp.getChangedColumns();
            var me = this;
            try {
                this.doEvent("onpickerclose", {objBUTTON:me,objMATRIX:me.cp.mtxTarget,arrCOLUMNSADDED:changed.added,arrCOLUMNSREMOVED:changed.removed});
            } catch(ex) {
                tibco.admin.Main.logException(ex);
            }
            delete this.cp;
        }
    }
  }
);